<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../../include.inc.jsp"%>
<div class="row">
    <div class="col-lg-12">
        <form id="formDlg" class="form-horizontal" role="form">
            <input type="hidden" id="id" name="id" value="${foodOrder.id}" />
            <input type="hidden" id="menuInfo" name="menuInfo"/>
            <input type="hidden" id="type" name="type"value="1"/>
            <!-- 数据权限 -->
            <input type="hidden" id="organizationId" name="organization.id" value="${organizationId}" /> 
            <div class="form-group">
                <label class="col-lg-2 control-label">手机号:</label><span class="text-danger">*</span>
                <div class="col-lg-9">
                    <input type="text" class="form-control" id="mobile" name="user.mobile" value="${foodOrder.user.mobile}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">选择菜品:</label><span class="text-danger">*</span>
                <div class="col-lg-9">
                    <input type="hidden" id="discount"/>
                    <input type="hidden" class="form-control" id="menuId" name="foodMenu.id" value="${foodOrder.foodMenu.id}" />
                    <input type="text" readonly="readonly" class="form-control" id="menuName" name="menuName" value="${foodOrder.foodMenu.name}" onclick="selectFoodMenu();"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">数量:</label><span class="text-danger">*</span>
                <div class="col-lg-9">
                    <input type="number" min="1" class="form-control" id="num" name="num" value="${foodOrder.num}" onkeyup="setOrderNum();"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">总价（元）:</label><span class="text-danger">*</span>
                <div class="col-lg-9">
                    <input type="text" readonly="readonly" class="form-control" id="total" name="total" value="${foodOrder.total}"/>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="${contextPath}/static/assets/js/jquery.hotkeys.js"></script>
<script type="text/javascript" src="${contextPath}/static/assets/js/bootstrap-wysiwyg.js"></script>
<script type="text/javascript">
function selectFoodMenu(){
	var ajaxSelectUrl = contextPath + '/manage/ordering/foodMenu/select';
	showSelectDlg("选择菜单",ajaxSelectUrl,["table-data1"],setSelectMenuValue);
}
function setSelectMenuValue(obj){
	$("#menuId").val(obj[0].id);
	$("#menuName").val(obj[0].name);
	$("#discount").val(obj[0].discount);
	$("#num").val(1)
	$("#total").val(obj[0].discount);
}
function setOrderNum(){
	$("#total").val($("#num").val() * $("#discount").val());
}
jQuery(function($) {
    $('#formDlg').validate({
        errorElement : 'span',
        errorClass : 'help-block',
        focusCleanup : false,
        focusInvalid : false,
        onsubmit : false,
        rules : {
            "user.mobile":{required:true,maxlength:11,minlength:11},
            "menuName":{required:true},
            "num":{required:true,min:1},
        },
        messages : {
            "user.mobile" : '请输入正确的手机号',
            "menuName" : '请选择菜品',
            "num" : '请输入正确的购买数量',
        },
        highlight : function(e) {
            $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
        },
        success : function(e) {
            $(e).closest('.form-group').removeClass('has-error').addClass('has-success');
            $(e).remove();
        },
    });
});
</script>